package com.lbc.service.impl;

import com.lbc.bean.entity.MessageBoard;
import com.lbc.common.utils.JwtUtils;
import com.lbc.dao.custom.CtMessageBoardMapper;
import com.lbc.dao.custom.CtUserMapper;
import com.lbc.service.MessageBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author xyl
 * @date 2021-03-29 10:02
 */
@Service
public class MessageBoardServiceImpl implements MessageBoardService {

    @Autowired
    private CtMessageBoardMapper messageBoardMapper;
    @Autowired
    private CtUserMapper userMapper;

    @Override
    public int add(String content) {
        MessageBoard mb= new MessageBoard();
        mb.setCreateBy(userMapper.selectByPrimaryKey(JwtUtils.getUserId()).getUsername());
        mb.setContent(content);
        mb.setCreateTime(new Date());
        return messageBoardMapper.insert(mb);
    }

    @Override
    public List<MessageBoard> list() {
        return messageBoardMapper.selectListVO();
    }
}
